package com.example.demo.controller.system;

import com.example.demo.annoation.Log;
import com.example.demo.bean.AjaxRes;
import com.example.demo.bean.sysmenu.SysMenuDO;
import com.example.demo.controller.BaseAdminController;
import com.example.demo.enums.BusinessType;
import com.example.demo.service.ISysMenuService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping(value = "/system/menu")
@RestController
public class SysMenuController extends BaseAdminController {

    @Resource
    private ISysMenuService sysMenuService;

    @GetMapping("/list")
    public AjaxRes list() {
        return AjaxRes.success(sysMenuService.getSysMenuListWithoutAction());
    }

    @GetMapping("/listAll")
    public AjaxRes listAll() {
        return AjaxRes.success(sysMenuService.getSysMenuAllList());
    }

    @PostMapping("/insert")
    @Log(title = "新增菜单", businessType = BusinessType.INSERT)
    public AjaxRes insert(@RequestBody SysMenuDO sysMenuDO) {
        return toAjax(sysMenuService.addSysMenu(sysMenuDO));
    }

    @DeleteMapping("/delete/{menuId}")
    @Log(title = "删除菜单", businessType = BusinessType.DELETE)
    public AjaxRes delete(@PathVariable("menuId") Long menuId) {
        return toAjax(sysMenuService.deleteSysMenu(new SysMenuDO().setMenuId(menuId)));
    }

    @GetMapping("/{menuId}")
    public AjaxRes query(@PathVariable("menuId") Long menuId) {
        return AjaxRes.success(sysMenuService.getSysMenu(new SysMenuDO().setMenuId(menuId)));
    }

    @PutMapping("/update")
    @Log(title = "更新菜单", businessType = BusinessType.UPDATE)
    public AjaxRes update(@RequestBody SysMenuDO sysMenuDO) {
        return toAjax(sysMenuService.updateSysMenu(sysMenuDO));
    }

    @GetMapping("/listAllActionByMenuId/{menuId}")
    public AjaxRes listAllActionByMenuId(@PathVariable("menuId") Long menuId) {
        return AjaxRes.success(sysMenuService.getAllActionByMenuId(new SysMenuDO().setMenuId(menuId)));
    }

}
